Skip to content

Conversation

ilonatommy
Copy link
Member

@ilonatommy ilonatommy commented May 19, 2025

AuthenticationState serialization and deserialization uses declarative persistive component state

In order to solve the problem with non-matching keys in server and WASM:

[ComputeKey] inputString: Microsoft.AspNetCore.Components.WebAssembly.Server.AuthenticationStateSerializer.CurrentAuthenticationState, key: FxhcJRjzApOTVwAvYgWa1WBUHPHfWkmCIHP3kZeqZrM=
[Persist] type: Microsoft.AspNetCore.Components.WebAssembly.Server.AuthenticationStateSerializer, propertyType: Microsoft.AspNetCore.Components.Authorization.AuthenticationStateData, key: FxhcJRjzApOTVwAvYgWa1WBUHPHfWkmCIHP3kZeqZrM=, result: Microsoft.AspNetCore.Components.Authorization.AuthenticationStateData

MonoPlatform.ts:234 [ComputeKey] inputString: Microsoft.AspNetCore.Components.WebAssembly.Authentication.DeserializedAuthenticationStateProvider.CurrentAuthenticationState, key: CVLw9+XoagHLvt9DAe/VnpkOSQt34nib18t39RUYuuw=
MonoPlatform.ts:234 [Restore] type: Microsoft.AspNetCore.Components.WebAssembly.Authentication.DeserializedAuthenticationStateProvider, propertyType: Microsoft.AspNetCore.Components.Authorization.AuthenticationStateData, key: CVLw9+XoagHLvt9DAe/VnpkOSQt34nib18t39RUYuuw=, result: 

A cast to same class on registration was needed. To do that, both serializer and deserializer had to inherit from the same class, e.g. AuthenticationStateProvider.

Description of changes

  • AuthenticationStateSerializer inherits now from AuthenticationStateProvider.
  • Added registration of AuthenticationStateSerializer on the server side to save the state.
  • Added registration of DeserializedAuthenticationStateProvider on the client side to restore the state.

Fixes #60718

@ilonatommy ilonatommy added this to the 10.0-preview5 milestone May 19, 2025
@ilonatommy ilonatommy self-assigned this May 19, 2025
@ilonatommy ilonatommy added the area-blazor Includes: Blazor, Razor Components label May 19, 2025
@ilonatommy
Copy link
Member Author

ilonatommy commented May 20, 2025

On CI we are hitting error that I cannot reproduce locally and that does not make sense to me:

[Severe] http://127.0.0.1:43441/subdir/_framework/blazor.web.js 0:160241 ManagedError: AggregateException_ctor_DefaultMessage (The type 'Microsoft.AspNetCore.Components.WebAssembly.Authentication.DeserializedAuthenticationStateProvider' declares a property matching the name 'CurrentAuthenticationState' that is not public. Persistent service properties must be public.)

The property is public

[SupplyParameterFromPersistentComponentState]
    public AuthenticationStateData? CurrentAuthenticationState { get; set; }

Maybe the fact that it's in internal class could affect it but DefaultAntiforgeryStateProvider andResourceColletionProvider are also internal classes and there, it was not a concern.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-blazor Includes: Blazor, Razor Components
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Blazor] Update AuthenticationStateProvider to take advantage of Declarative persistent component state
2 participants